package com.example.bgmachine.bgmachine.handlouts;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.example.bgmachine.bgmachine.R;
import com.example.bgmachine.bgmachine.goods.HomepageGridRightMenuAdapter;
import com.example.bgmachine.bgmachine.goods.HomepageGridRightMenuItemData;
import com.example.bgmachine.bgmachine.orders.OrderContentAdapter;
import com.example.bgmachine.bgmachine.orders.OrderContentData;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class HandloutFragment extends Fragment {
    private Context mContext = null;

    private GridView order_infor_item_gridvew = null;
    private ArrayList<HomepageGridRightMenuItemData> mHomepageGridRightMenuItemData = new ArrayList<HomepageGridRightMenuItemData>();
    private HomepageGridRightMenuAdapter mHomepageGridRightMenuAdapter = null;
    private int m_numbers =0;
    public HandlContentAdapter mHandlContentAdapter = null;
    public List<HandlContentData> mHandlContentData = null;
    public HandloutFragment() {

    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container, @NonNull Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.hanld_out_fragment_layout, container, false);
        mContext =view.getContext();
        order_infor_item_gridvew =  view.findViewById(R.id.order_infor_item_gridvew);
        mHandlContentData = new LinkedList<HandlContentData>();
        mHandlContentAdapter = new HandlContentAdapter(mContext,(LinkedList<HandlContentData>) mHandlContentData);
        if (order_infor_item_gridvew != null) {
            order_infor_item_gridvew.setAdapter(mHandlContentAdapter);
        }
        return view;
    }

    public void  addItem(HandlContentData orderContentData){
        if (mHandlContentAdapter != null) {
            mHandlContentAdapter.add(orderContentData);

            mHandlContentAdapter.notifyDataSetChanged();

        }
        m_numbers++;
    }


    public void  handlLens(){

        int lens1=0;
        lens1= m_numbers / 3 ;
        if( (m_numbers % 3) > 0 ){
            lens1++;
        }
        ViewGroup.LayoutParams layoutParams = order_infor_item_gridvew.getLayoutParams();// new LinearLayout.LayoutParams((int) mContext.getResources().getDimension(R.dimen.home_material_text_with), (int) mContext.getResources().getDimension(R.dimen.home_material_text_height));

        layoutParams.height = lens1 * (int) mContext.getResources().getDimension(R.dimen.handl_item_height);
        Log.d("aaa", "layoutParams.height ==" + String.valueOf(layoutParams.height));
        order_infor_item_gridvew.setLayoutParams(layoutParams);

    }
}
